package com.zhiche.lisa.lspm.service.carrier.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zhiche.lisa.core.enums.TableStatusEnum;
import com.zhiche.lisa.lspm.dao.mapper.carrier.CarrierDictionaryMapper;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierDictionary;
import com.zhiche.lisa.lspm.service.carrier.CarrierDictionaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 基础数据字典 服务实现类
 * </p>
 *
 * @author qichao
 * @since 2018-11-09
 */
@Service
public class CarrierDictionaryServiceImpl extends ServiceImpl<CarrierDictionaryMapper, CarrierDictionary> implements CarrierDictionaryService {

    /**
     * 查询carrier 基础字典信息
     */
    @Override
    public List<CarrierDictionary> queryDictionary(Page<CarrierDictionary> page) {
        EntityWrapper<CarrierDictionary> cdEW = new EntityWrapper<>();
        if (page != null) {
            Map<String, Object> condition = page.getCondition();
            if (condition != null && !condition.isEmpty()) {
                if (condition.get("code") != null && StringUtils.isNotBlank(condition.get("code").toString())) {
                    cdEW.eq("code", condition.get("code").toString());
                }
                if (condition.get("name") != null && StringUtils.isNotBlank(condition.get("name").toString())) {
                    cdEW.eq("name", condition.get("name").toString());
                }
                if (condition.get("bussinessType") != null && StringUtils.isNotBlank(condition.get("bussinessType").toString())) {
                    cdEW.eq("bussiness_type", condition.get("bussinessType").toString());
                }
            }
        }
        cdEW.eq("status", TableStatusEnum.STATUS_10.getCode())
                .orderBy("id", false);
        return baseMapper.selectPageNoTenant(page, cdEW);
    }
}
